package cn.htsyb.synergy.security.bean.param;

import cn.htsyb.synergy.orm.jpa.criterion.ExpressBuilder;
import cn.htsyb.synergy.orm.jpa.criterion.QueryExpress;
import cn.htsyb.synergy.orm.jpa.model.param.AbsStandardParam;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Getter;
import lombok.Setter;
import org.springframework.util.StringUtils;

import java.util.List;
/**
 * 数据授权 参数类
 * codeMaker at 2020-07-14
 * @author lakeside hubin_yuan.410@hotmail.com
 * @since 2020-07-14
 */
@Setter
@Getter
@Schema(description = "数据授权参数")
public class SecurityDataAuthorizeParam extends AbsStandardParam {
    /**指定组织列表*/
    @Schema(name = "appointOrganize", description = "指定组织列表 ")
    protected  String appointOrganize;
    /**指定角色列表*/
    @Schema(name = "appointRole", description = "指定角色列表 ")
    protected  String appointRole;
    /**指定用户列表*/
    @Schema(name = "appointUser", description = "指定用户列表 ")
    protected  String appointUser;
    /**授权指令*/
    @Schema(name = "dataAuthorizeEl", description = "授权指令 ")
    protected  String dataAuthorizeEl;

    /**通用过滤*/
    @Schema(name = "filter", description = "通用过滤")
    protected String filter;

    @Override
    public List<QueryExpress> searchCriterion() {
        return ExpressBuilder.instance(super.searchCriterion())
                    .addExpressOfOperator(!StringUtils.isEmpty(appointOrganize), "appointOrganize", QueryExpress.Operator.EQ, appointOrganize)
                    .addExpressOfOperator(!StringUtils.isEmpty(appointRole), "appointRole", QueryExpress.Operator.EQ, appointRole)
                    .addExpressOfOperator(!StringUtils.isEmpty(appointUser), "appointUser", QueryExpress.Operator.EQ, appointUser)
                    .addExpressOfOperator(!StringUtils.isEmpty(dataAuthorizeEl), "dataAuthorizeEl", QueryExpress.Operator.EQ, dataAuthorizeEl)
                .build();
    }

    @Override
    public List<QueryExpress> filterCriterion() {
        boolean bool=!StringUtils.isEmpty(filter);

        return ExpressBuilder.instance(super.filterCriterion())
                /*需要自行根据索引调整可支持的通用查询字段，切不可全字段通用查询
                .addExpressOfOperator(bool,"appointOrganize",QueryExpress.Operator.LIKE, filter)
                .addExpressOfOperator(bool,"appointRole",QueryExpress.Operator.LIKE, filter)
                .addExpressOfOperator(bool,"appointUser",QueryExpress.Operator.LIKE, filter)
                .addExpressOfOperator(bool,"dataAuthorizeEl",QueryExpress.Operator.LIKE, filter)
                 */
                .build();
    }
}